package cn.medemede.k1;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        ArrayList<Shape> shapeArrayList=new ArrayList<>();
        Scanner cin=new Scanner(System.in);
        int x;
        while (true) {
            System.out.println(
                    "-----图形类对象的管理-----\n" +
                            "------------------------\n" +
                            "1.创建一个圆\n" +
                            "2.创建一个矩形\n" +
                            "3.创建一个长方体\n" +
                            "4.创建一个圆柱体\n" +
                            "5.显示已创建的图形\n" +
                            "6.求面积之和\n" +
                            "7.求周长之和\n"+
                            "8.退出");
            x=cin.nextInt();
            if(x>7||x<1)
                break;
            switch (x){
                case 1:
                    Circle circle=new Circle();
                    System.out.println("请输入圆的半径：");
                    circle.r=cin.nextDouble();
                    shapeArrayList.add(circle);
                    break;
                case 2:
                    Rectangle rectangle=new Rectangle();
                    System.out.println("请输入矩形的长和宽：");
                    rectangle.x=cin.nextDouble();
                    rectangle.y=cin.nextDouble();
                    shapeArrayList.add(rectangle);
                    break;
                case 3:
                    Cube cube=new Cube();
                    System.out.println("请输入长宽高：");
                    cube.x=cin.nextDouble();
                    cube.y=cin.nextDouble();
                    cube.z=cin.nextDouble();
                    shapeArrayList.add(cube);
                    break;
                case 4:
                    Clinder clinder=new Clinder();
                    System.out.println("请输入底面半径和高：");
                    clinder.r=cin.nextDouble();
                    clinder.h=cin.nextDouble();
                    shapeArrayList.add(clinder);
                    break;
                case 5:
                    for (Shape aShapeArrayList : shapeArrayList) {
                        aShapeArrayList.show();
                    }
                    break;
                case 6:
                    double sum=0.0;
                    for (Shape aShapeArrayList : shapeArrayList) {
                        sum += aShapeArrayList.area();
                    }
                    System.out.println("面积之和为："+sum);
                    break;
                case 7:
                    sum = 0.0;
                    for (Shape aShapeArrayList : shapeArrayList) {
                        sum += aShapeArrayList.perimeter();
                    }
                    System.out.println("周长之和为："+sum);
                    default:
                        break;
            }
        }

    }

}
